package com.example.config;

import com.example.util.ZKUtil;
import org.apache.zookeeper.ZooKeeper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;

public class TestConfig {

    private ZooKeeper zk;

    @Before
    public void before() {
        zk = ZKUtil.getZKClient();
    }

    @After
    public void after() {
        try {
            zk.close();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void config() {

        String path = "/AppConf";

//        MyConf myConf = new MyConf();

        WatchCallback watchCallback = new WatchCallback(zk, path);

        watchCallback.aWait();


        // 配置改变后


        while (true) {
            if (watchCallback.getConf().getConf() == null) {
                watchCallback.aWait();
            }
            System.out.println("myConf == " + watchCallback.getConf().getConf()+ "         thread name == " + Thread.currentThread().getName());
            try {
                Thread.sleep(1111);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }







    }


}
